/* Author.m
 *
 * You may freely copy, distribute, and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
 * fitness for any particular use.
 *
 * This simple Enterprise Object only takes care of the archiving
 * functions. Note that you can add the accessor methods, and other
 * specific functionality as well.  
 
 *
 * Written by: Dan Willhite, NeXT Engineering
 */

#import "Author.h"

@implementation Author

- init
{
    [super init];
    return self;
}

- free
{   
    [authorID autorelease];
    [firstname autorelease];
    [lastname autorelease];
    [address autorelease];
    [city autorelease];
    [state autorelease];
    [zip autorelease];
    [phone autorelease];
    
    return [super free];
}


- (NSString *)id { return [NSString stringWithFormat:@"%X", self]; }

- write:(NXTypedStream *)stream;
{
    [super write:stream];
    
    NXWriteNSObject(stream, authorID);
    NXWriteNSObject(stream, firstname);
    NXWriteNSObject(stream, lastname);
    NXWriteNSObject(stream, address);
    NXWriteNSObject(stream, city);
    NXWriteNSObject(stream, state);
    NXWriteNSObject(stream, zip);
    NXWriteNSObject(stream, phone);
    NXWriteTypes(stream, "i", &contract);
    return self;
}

- read:(NXTypedStream *)stream;
{
    [super read:stream];
    
    authorID = [(NSString *)NXReadNSObject(stream) retain];
    firstname = [(NSString *)NXReadNSObject(stream) retain];
    lastname = [(NSString *)NXReadNSObject(stream) retain];
    address = [(NSString *)NXReadNSObject(stream) retain];
    city = [(NSString *)NXReadNSObject(stream) retain];
    state = [(NSString *)NXReadNSObject(stream) retain];
    zip = [(NSString *)NXReadNSObject(stream) retain];
    phone = [(NSString *)NXReadNSObject(stream) retain];
    NXReadTypes(stream, "i", &contract);
    return self;
}

- (NSString *)description
{
    NSMutableString *string;
    
    string = [NSMutableString stringWithFormat:@"{\n"];
    [string appendFormat:@"\tauthorID = %@\n", authorID];
    [string appendFormat:@"\tfirstname = %@\n", firstname];
    [string appendFormat:@"\tlastname = %@\n", lastname];
    [string appendFormat:@"\taddress = %@\n", address];
    [string appendFormat:@"\tcity = %@\n", city];
    [string appendFormat:@"\tstate = %@\n", state];
    [string appendFormat:@"\tzip = %@\n", zip];
    [string appendFormat:@"\tphone = %@\n", phone];
    [string appendFormat:@"\tcontract = %d\n", contract];
    [string appendFormat:@"}\n", address];

    return string;
}



@end